﻿// JavaScript Document
$(document).ready(init)
var speed=500;
function init() {

    var tab = new idTabs("#idTabs", "menuon1");
    tab.init();

    $("#receivePresent .user_list:even").removeClass("on");
    $("#receivePresent .user_list:odd").addClass("on");

	addListener();
}
function addListener(){
	$(window).scroll(function(){
					var top=document.documentElement.scrollTop + 70;
					var left=document.documentElement.scrollLeft + 2;
					if (navigator.userAgent.indexOf('Safari') != -1) {
							top = window.scrollY + 70;
							left = window.scrollX + 2;
					 }
					//$("#parcars").css("top",top + "px").css("left",left + "px");	
					$("#parcars").animate({top:top + "px",left:left + "px"},100);
				});	
}
function getSendPresent(target) {
    var ctrl = null;
    try {
        ctrl = getBusyOverlay(document.body);
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }
    $("#sendPresent").load("/testIphoneUI/test13.html?type=getSend", function() {
        if (ctrl != null) { ctrl.remove(); }
        $("#sendPresent .user_list:odd").addClass("on");
    });
}

function getMoreReceive(target) {
    var ctrl = null;
    try {
        ctrl = getBusyOverlay(target.parentNode);
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }
    var lastList = $("#receivePresent .user_list:last").get(0);
    $.ajax({ url: "/tools/ajax.aspx?type=premore&minid=" + lastList.id,	
        dataType: "html",
        success: function(data) {
            if (ctrl != null) { ctrl.remove(); }
            if (data != "") {
                $(data).insertAfter(lastList);
                $("#receivePresent .user_list:even").removeClass("on");
                $("#receivePresent .user_list:odd").addClass("on");
            }
            else $(target).hide();
        } 
    });
}
function getMoreSend(target) {
    var ctrl = null;
    try {
        ctrl = getBusyOverlay(target.parentNode);
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }

    var lastList = $("#sendPresent .user_list:last").get(0);

    $.ajax({ url: "/tools/ajax.aspx?type=presendmore&minid=" + lastList.id,	
        dataType: "html",
        success: function(data) {
            if (ctrl != null) { ctrl.remove(); }
            if (data != "") {
                $(data).insertAfter(lastList);
                $("#sendPresent .user_list:even").removeClass("on");
                $("#sendPresent .user_list:odd").addClass("on");
            }
            else $(target).hide();
        } 
    });
}
function deleteReceive(target) {
    var list = $(target).parents("#receivePresent .user_list").get(0);
    var btnArray = [{ name: 'YES', text: '确 定', def: true }, { name: 'NO', text: '取 消'}]
    var box = new alertBox("是否确认删除此条记录？", null, btnArray, true);
    box.NO.onclick = function() { box.hide() }
    box.YES.onclick = function() {
        deletePresent(list, "delRecv");
        box.hide();
    }
}
function deleteSend(target) {
    var list = $(target).parents("#sendPresent .user_list").get(0);
    var btnArray = [{ name: 'YES', text: '确 定', def: true }, { name: 'NO', text: '取 消'}]
    var box = new alertBox("是否确认删除此条记录？", null, btnArray, true);
    box.NO.onclick = function() { box.hide() }
    box.YES.onclick = function() {
        deletePresent(list, "delSend");
        box.hide();
    }
}
function deletePresent(list, type) {
    var ctrl = null;
    try {
        ctrl = getBusyOverlay(list);
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }

    $.ajax({ url: "/tools/ajax.aspx?type=delpresent&types=" + type + "&presentID=" + list.id,
        dataType: "html",
        success: function(data) {
            if (ctrl != null) { ctrl.remove(); }
            if (data == "ok") {
                $(list).remove();
                $(".user_list:even").removeClass("on");
                $(".user_list:odd").addClass("on");
                msgBox("删除记录成功！")
            }
            else {
                msgBox("删除记录失败！")
            }
        } 
    });
}

function ShowCars(carid, userid) {
    var ctrl = null;
    try {
        ctrl = getBusyOverlay(document.body);
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }
    $.ajax({ url: "/tools/ajax.aspx?type=precars&preid=" + carid + "&uid=" + userid, cache: false,
        dataType: "html",
        success: function(data) {
            if (ctrl != null) { ctrl.remove(); }
            document.getElementById("parcars").innerHTML = data;
			$("#parcars").animate({opacity:"show"},speed);
        }
    });
}
function closeCard(){
	$("#parcars").animate({opacity:"hide"},speed);
}
	